package com.sr.examination.exam.result;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.sr.examination.R;
import com.sr.examination.common.event.CodeConstant;
import com.sr.examination.exam.common.adapter.NumberCardAdapter;
import com.sr.examination.exam.exercise.ExerciseActivity;
import com.tl.commonlibrary.tool.NumberUnit;
import com.tl.commonlibrary.tool.UIUtils;
import com.tl.commonlibrary.ui.BaseFragmentActivity;
import com.tl.commonlibrary.ui.beans.ExerciseBean;
import com.tl.commonlibrary.ui.beans.ExerciseListBean;
import com.tl.commonlibrary.ui.beans.ExerciseOption;
import com.tl.commonlibrary.ui.widget.CustomAlertDialog;
import com.tl.commonlibrary.ui.widget.TitleBar;

import java.util.ArrayList;
import java.util.List;

/**
 * 答题结果，答题报告
 * Created by JongSung on 18/2/10.
 */

public class ResultActivity extends BaseFragmentActivity implements AdapterView.OnItemClickListener {
    public static void start(Context context, String examTitle, long examId, ExerciseListBean exerciseListBean) {
        Intent starter = new Intent(context, ResultActivity.class);
        starter.putExtra("ExerciseListBean", exerciseListBean);
        starter.putExtra("examTitle", examTitle);
        starter.putExtra("examId", examId);
        context.startActivity(starter);
    }

    private GridView singleChoiceGView, multipleChoiceGView, judgementChoiceGView, subjectiveGView, caseAnalysisGView, calculationGView, inTrayGView;
    private ExerciseListBean exerciseListBean;
    private ArrayList<ExerciseBean> singleChoiceBeans, multipleChoiceBeans, judgementChoiceBeans, subjectiveBeans, shortAnswerBeans, wrongAnswerBeans, allAnswerBeans, caseAnalysisBeans, calculationBeans, inTrayBeans;
    private NumberCardAdapter singleChoiceAdapter, multipleChoiceAdapter, judgementChoiceAdapter, shortAnswerAdapter, caseAnalysisAdapter, calculationAdapter, inTrayAdapter;
    private TextView scoreTView, usedTimeTView, subjectiveScoreBtn, containSubjectiveTView;
    private String examTitle;
    private long examId;
    private boolean includeSubjectvieScore = false;//是否包含主观得分

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_result);
        exerciseListBean = (ExerciseListBean) getIntent().getSerializableExtra("ExerciseListBean");
        if (exerciseListBean == null) {
            UIUtils.showToast(getString(R.string.hint_not_find_number_card));
            finish();
            return;
        }
        examTitle = getIntent().getStringExtra("examTitle");
        examId = getIntent().getLongExtra("examId", 0);
        setTitle(getString(R.string.exam_result_report));
        showLoading();
        singleChoiceGView = findViewById(R.id.singleChoiceGView);
        multipleChoiceGView = findViewById(R.id.multipleChoiceGView);
        judgementChoiceGView = findViewById(R.id.judgementChoiceGView);
        subjectiveGView = findViewById(R.id.subjectiveGView);
        caseAnalysisGView = findViewById(R.id.caseAnalysisGView);
        calculationGView = findViewById(R.id.calculationGView);
        inTrayGView = findViewById(R.id.inTrayGView);
        scoreTView = findViewById(R.id.scoreTView);
        subjectiveScoreBtn = findViewById(R.id.subjectiveScoreBtn);
        usedTimeTView = findViewById(R.id.usedTimeTView);
        containSubjectiveTView = findViewById(R.id.containSubjectiveTView);
        getTitleBar().addAction(new TitleBar.TextAction(getString(R.string.exam_re_exam)) {
            @Override
            public void performAction(View view) {
                showExitDialog();
            }
        });
        findViewById(R.id.wrongAnswerBtn).setOnClickListener(this);
        findViewById(R.id.allAnswerBtn).setOnClickListener(this);
        subjectiveScoreBtn.setOnClickListener(this);
        findViewById(R.id.containerLayout).setVisibility(View.GONE);
        categoryNumberCard();
    }

    private void initData() {
        if (includeSubjectvieScore) {
            containSubjectiveTView.setText(R.string.exam_result_include_subjective_score);
            subjectiveScoreBtn.setVisibility(View.GONE);
        } else {
            containSubjectiveTView.setText(R.string.exam_result_un_include_subjective_score);
            subjectiveScoreBtn.setVisibility(View.VISIBLE);
        }
        int start = 0;
        if (singleChoiceBeans != null && !singleChoiceBeans.isEmpty()) {
            singleChoiceAdapter = new NumberCardAdapter(context, singleChoiceBeans).setStart(start);
            singleChoiceGView.setOnItemClickListener(this);
            singleChoiceGView.setAdapter(singleChoiceAdapter);
            start += singleChoiceBeans.size();
        } else {
            findViewById(R.id.singleChoiceLayout).setVisibility(View.GONE);
        }
        if (multipleChoiceBeans != null && !multipleChoiceBeans.isEmpty()) {
            multipleChoiceAdapter = new NumberCardAdapter(context, multipleChoiceBeans).setStart(start);
            multipleChoiceGView.setOnItemClickListener(this);
            multipleChoiceGView.setAdapter(multipleChoiceAdapter);
            start += multipleChoiceBeans.size();
        } else {
            findViewById(R.id.multipleChoiceLayout).setVisibility(View.GONE);
        }
        if (judgementChoiceBeans != null && !judgementChoiceBeans.isEmpty()) {
            judgementChoiceAdapter = new NumberCardAdapter(context, judgementChoiceBeans).setStart(start);
            judgementChoiceGView.setOnItemClickListener(this);
            judgementChoiceGView.setAdapter(judgementChoiceAdapter);
            start += judgementChoiceBeans.size();
        } else {
            findViewById(R.id.judgementChoiceLayout).setVisibility(View.GONE);
        }
        if (shortAnswerBeans != null && !shortAnswerBeans.isEmpty()) {
            shortAnswerAdapter = new NumberCardAdapter(context, shortAnswerBeans).setStart(start);
            subjectiveGView.setOnItemClickListener(this);
            subjectiveGView.setAdapter(shortAnswerAdapter);
            start += shortAnswerBeans.size();
        } else {
            subjectiveScoreBtn.setVisibility(View.GONE);
            findViewById(R.id.subjectiveLayout).setVisibility(View.GONE);
        }
        if (caseAnalysisBeans != null && !caseAnalysisBeans.isEmpty()) {
            caseAnalysisAdapter = new NumberCardAdapter(context, caseAnalysisBeans).setStart(start);
            caseAnalysisGView.setOnItemClickListener(this);
            caseAnalysisGView.setAdapter(caseAnalysisAdapter);
            start += caseAnalysisBeans.size();
        } else {
            findViewById(R.id.caseAnalysisLayout).setVisibility(View.GONE);
        }
        if (calculationBeans != null && !calculationBeans.isEmpty()) {
            calculationAdapter = new NumberCardAdapter(context, calculationBeans).setStart(start);
            calculationGView.setOnItemClickListener(this);
            calculationGView.setAdapter(calculationAdapter);
            start += calculationBeans.size();
        } else {
            findViewById(R.id.calculationLayout).setVisibility(View.GONE);
        }
        if (inTrayBeans != null && !inTrayBeans.isEmpty()) {
            inTrayAdapter = new NumberCardAdapter(context, inTrayBeans).setStart(start);
            inTrayGView.setOnItemClickListener(this);
            inTrayGView.setAdapter(inTrayAdapter);
            start += inTrayBeans.size();
        } else {
            findViewById(R.id.inTrayLayout).setVisibility(View.GONE);
        }
        setTotalScore();
        usedTimeTView.setText(getString(R.string.exam_used_time, ExerciseListBean.getExerciseTimeFormat(context)));
        findViewById(R.id.containerLayout).setVisibility(View.VISIBLE);
    }

    private void setTotalScore() {

        SpannableString tempSpan = null;
        NumberUnit numberUnit = new NumberUnit();
        numberUnit.setFormatDot(false);
        ArrayList<String> scores = new ArrayList<>();
        if (singleChoiceBeans != null && !singleChoiceBeans.isEmpty()) {
            numberUnit.set(exerciseListBean.getSingleChoiceScore());
            scores.add(numberUnit.get2F());
        }
        if (multipleChoiceBeans != null && !multipleChoiceBeans.isEmpty()) {
            numberUnit.set(exerciseListBean.getMultiChoiceScore());
            scores.add(numberUnit.get2F());

        }
        if (judgementChoiceBeans != null && !judgementChoiceBeans.isEmpty()) {
            numberUnit.set(exerciseListBean.getTrueOrFalseScore());
            scores.add(numberUnit.get2F());

        }
        if (shortAnswerBeans != null && !shortAnswerBeans.isEmpty()) {
            numberUnit.set(exerciseListBean.getShortAnswerScore());
            scores.add(numberUnit.get2F());
        }

        if (caseAnalysisBeans != null && !caseAnalysisBeans.isEmpty()) {
            numberUnit.set(exerciseListBean.getAnalysisQuestScore());
            scores.add(numberUnit.get2F());
        }

        if (calculationBeans != null && !calculationBeans.isEmpty()) {
            numberUnit.set(exerciseListBean.getCalcQuestScore());
            scores.add(numberUnit.get2F());
        }

        if (inTrayBeans != null && !inTrayBeans.isEmpty()) {
            numberUnit.set(exerciseListBean.getOfficialDocScore());
            scores.add(numberUnit.get2F());
        }
        if (scores == null || scores.size() < 1) {
            numberUnit.set(exerciseListBean.getTotalScore());
            String totalScoreStr = numberUnit.get2F();
            tempSpan = new SpannableString(totalScoreStr + "分");
            tempSpan.setSpan(new AbsoluteSizeSpan(context.getResources().getDimensionPixelSize(R.dimen.base_40px)), 0, totalScoreStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        } else {
            StringBuilder scoreBuilder = new StringBuilder();
            for (int i = 0; i < scores.size(); i++) {
                scoreBuilder.append(scores.get(i)).append("分").append(i < scores.size() - 1 ? "+" : "=");
            }
            numberUnit.set(exerciseListBean.getTotalScore());
            String totalScoreStr = numberUnit.get2F();
            scoreBuilder.append(totalScoreStr).append("分");
            tempSpan = new SpannableString(scoreBuilder.toString());
            int start = 0, end = 0;
            for (int i = 0; i < scores.size(); i++) {
                end = start + scores.get(i).length();
                tempSpan.setSpan(new AbsoluteSizeSpan(context.getResources().getDimensionPixelSize(R.dimen.base_40px)), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                start += scores.get(i).length() + 1 + 1;//"分"和"+"和+"="都占一位
            }
            end = start + totalScoreStr.length();
            tempSpan.setSpan(new AbsoluteSizeSpan(context.getResources().getDimensionPixelSize(R.dimen.base_40px)), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        }
        if (tempSpan != null) {
            scoreTView.setText(tempSpan);
        }
    }

    private Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            if (msg.what == HANDLER_CATEGORY_START) {
                showLoading();
            } else if (msg.what == HANDLER_CATEGORY_SUCCESS) {
                initData();
                dismissLoading();
            } else if (msg.what == HANDLER_CATEGORY_FAILED) {
                dismissLoading();
            }
            return false;
        }
    });
    private static final int HANDLER_CATEGORY_START = 0;
    private static final int HANDLER_CATEGORY_SUCCESS = 1;
    private static final int HANDLER_CATEGORY_FAILED = 2;

    /**
     * 处理试卷题目，分类等
     */
    private void categoryNumberCard() {
        handler.sendEmptyMessage(HANDLER_CATEGORY_START);
        new Thread(new Runnable() {
            @Override
            public void run() {
                includeSubjectvieScore = false;
                if (allAnswerBeans != null) {
                    allAnswerBeans.clear();
                    allAnswerBeans = null;
                }
                if (wrongAnswerBeans != null) {
                    wrongAnswerBeans.clear();
                    wrongAnswerBeans = null;
                }
                if (singleChoiceBeans != null) {
                    singleChoiceBeans.clear();
                    singleChoiceBeans = null;
                }
                if (multipleChoiceBeans != null) {
                    multipleChoiceBeans.clear();
                    multipleChoiceBeans = null;
                }
                if (judgementChoiceBeans != null) {
                    judgementChoiceBeans.clear();
                    judgementChoiceBeans = null;
                }
                if (subjectiveBeans != null) {
                    subjectiveBeans.clear();
                    subjectiveBeans = null;
                }
                if (shortAnswerBeans != null) {
                    shortAnswerBeans.clear();
                    shortAnswerBeans = null;
                }
                if (caseAnalysisBeans != null) {
                    caseAnalysisBeans.clear();
                    caseAnalysisBeans = null;
                }
                if (calculationBeans != null) {
                    calculationBeans.clear();
                    calculationBeans = null;
                }
                if (inTrayBeans != null) {
                    inTrayBeans.clear();
                    inTrayBeans = null;
                }
                if (allAnswerBeans != null) {
                    allAnswerBeans.clear();
                    allAnswerBeans = null;
                }
                ArrayList<ExerciseBean> exerciseBeans = exerciseListBean.getPaperItems();
                if (exerciseBeans != null && !exerciseBeans.isEmpty()) {
                    for (ExerciseBean tempBean : exerciseBeans) {
                        if (tempBean != null) {
                            //把数据调整成查看解析模式
                            tempBean.setDisplayMode(ExerciseBean.DISPLAY_MODE_ANALYSIS);
                            if (tempBean.isSingleChoose()) {
                                //装载单选题
                                if (singleChoiceBeans == null) {
                                    singleChoiceBeans = new ArrayList<>();
                                }
                                singleChoiceBeans.add(tempBean);
                            } else if (tempBean.isMultipleChoose()) {
                                //装载多选题
                                if (multipleChoiceBeans == null) {
                                    multipleChoiceBeans = new ArrayList<>();
                                }
                                multipleChoiceBeans.add(tempBean);
                            } else if (tempBean.isJudgementChoose()) {
                                //装载判断题
                                if (judgementChoiceBeans == null) {
                                    judgementChoiceBeans = new ArrayList<>();
                                }
                                judgementChoiceBeans.add(tempBean);
                            } else if (tempBean.isShortAnswer()) {
                                //装载简答题
                                if (shortAnswerBeans == null) {
                                    shortAnswerBeans = new ArrayList<>();
                                }
                                shortAnswerBeans.add(tempBean);
//                                //装载自评分题（简答题中没有评分的题目）
//                                if (!tempBean.hasMyScore()) {
//                                    if (subjectiveScoreBeans == null) {
//                                        subjectiveScoreBeans = new ArrayList<>();
//                                    }
//                                }
                                addSubjectBeans(tempBean);
                                //是否已经提交了主观自评分
                                if (!includeSubjectvieScore) {
                                    includeSubjectvieScore = tempBean.hasMyScore();
                                }
                            } else if (tempBean.isCaseAnalysis()) {
                                //装载案例分析题
                                if (caseAnalysisBeans == null) {
                                    caseAnalysisBeans = new ArrayList<>();
                                }
                                caseAnalysisBeans.add(tempBean);
                                addSubjectBeans(tempBean);
                                //是否已经提交了主观自评分
                                if (!includeSubjectvieScore) {
                                    includeSubjectvieScore = tempBean.hasMyScore();
                                }
                            } else if (tempBean.isCalculation()) {
                                //装载案例分析题
                                if (calculationBeans == null) {
                                    calculationBeans = new ArrayList<>();
                                }
                                calculationBeans.add(tempBean);
                                addSubjectBeans(tempBean);
                                //是否已经提交了主观自评分
                                if (!includeSubjectvieScore) {
                                    includeSubjectvieScore = tempBean.hasMyScore();
                                }
                            } else if (tempBean.isInTray()) {
                                //装载案例分析题
                                if (inTrayBeans == null) {
                                    inTrayBeans = new ArrayList<>();
                                }
                                inTrayBeans.add(tempBean);
                                addSubjectBeans(tempBean);
                                //是否已经提交了主观自评分
                                if (!includeSubjectvieScore) {
                                    includeSubjectvieScore = tempBean.hasMyScore();
                                }
                            }
                            //装载错题
                            if (tempBean.answerWrong()) {
                                if (wrongAnswerBeans == null) {
                                    wrongAnswerBeans = new ArrayList<>();
                                }
                                wrongAnswerBeans.add(tempBean);
                            }
                            //装载所有题目
                            if (allAnswerBeans == null) {
                                allAnswerBeans = new ArrayList<>();
                            }
                            allAnswerBeans.add(tempBean);
                        }
                    }
                    handler.sendEmptyMessage(HANDLER_CATEGORY_SUCCESS);
                } else {
                    handler.sendEmptyMessage(HANDLER_CATEGORY_FAILED);
                }
            }
        }).start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.wrongAnswerBtn://错题解析
                if (wrongAnswerBeans == null || wrongAnswerBeans.isEmpty()) {
                    UIUtils.showToast(getString(R.string.hint_wrong_answer_null));
                    return;
                }
                exerciseListBean.resetPaperItems(wrongAnswerBeans);
                exerciseListBean.setItemTotal(wrongAnswerBeans.size());
                setChoiceChooseItemAndSubjectDisplayModeItem(wrongAnswerBeans, ExerciseBean.DISPLAY_MODE_ANALYSIS);
                ExerciseActivity.start(context, examTitle, examId, ExerciseListBean.TYPE_RESULT_WRONG_ANSWER_ANALYSIS, exerciseListBean);
                break;
            case R.id.allAnswerBtn://所有解析
                exerciseListBean.resetPaperItems(allAnswerBeans);
                exerciseListBean.setItemTotal(allAnswerBeans.size());
                setChoiceChooseItemAndSubjectDisplayModeItem(allAnswerBeans, ExerciseBean.DISPLAY_MODE_ANALYSIS);
                ExerciseActivity.start(context, examTitle, examId, ExerciseListBean.TYPE_RESULT_ALL_ANALYSIS, exerciseListBean);
                break;
            case R.id.subjectiveScoreBtn://主观题自评分
                if (subjectiveBeans == null || subjectiveBeans.isEmpty()) {
                    return;
                }
                exerciseListBean.resetPaperItems(subjectiveBeans);
                exerciseListBean.setItemTotal(subjectiveBeans.size());
                setChoiceChooseItemAndSubjectDisplayModeItem(subjectiveBeans, ExerciseBean.DISPLAY_MODE_ANALYSIS_MARK);
                ExerciseActivity.startForResult(this, examTitle, examId, ExerciseListBean.TYPE_RESULT_SUBJECTIVE_SCORE, exerciseListBean, CodeConstant.EXERCISE_SUBJECTIVE_SCORE_SELF);
                break;
        }
    }

    private void addSubjectBeans(ExerciseBean exerciseBean) {
        if (exerciseBean == null) {
            return;
        }
        if (subjectiveBeans == null) {
            subjectiveBeans = new ArrayList<>();
        }
        subjectiveBeans.add(exerciseBean);
    }

    /**
     * 解析模式下，选择题需要将答案分拆到选项中，主观题需要设置显示模式
     */
    private void setChoiceChooseItemAndSubjectDisplayModeItem(ArrayList<ExerciseBean> beans, int mode) {
        List<ExerciseOption> options;
        for (ExerciseBean bean : beans) {
            //主观题不需要展示输入框中的答案，但要设置展示模式，是解析模式还是自评分模式
            if (bean.isSubjective()) {
                bean.setDisplayMode(mode);
            }
            //单选和判断题直接获取结果匹配
            if (bean.isJudgementChoose() || bean.isSingleChoose()) {
                options = bean.getOptions();
                if (!TextUtils.isEmpty(bean.getUserAnswer())) {
                    for (ExerciseOption op : options) {
                        if (bean.getUserAnswer().equals(op.getId())) {
                            op.setChecked(true);
                            break;
                        }
                    }
                }
            }
            //多选需要多次匹配结果
            else if (bean.isMultipleChoose()) {
                options = bean.getOptions();
                if (!TextUtils.isEmpty(bean.getUserAnswer())) {
                    for (ExerciseOption op : options) {
                        if (bean.getUserAnswer().contains(op.getId())) {
                            op.setChecked(true);
                        }
                    }
                }
            }
        }
    }

    private void displayModeForShortAnswerBean(int mode) {
        for (ExerciseBean tempBean : shortAnswerBeans) {
            tempBean.setDisplayMode(mode);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //自评分返回
        if (requestCode == CodeConstant.EXERCISE_SUBJECTIVE_SCORE_SELF) {
            if (resultCode == RESULT_OK) {
                if (data != null) {
                    //获取已经自评分的结果
                    subjectiveBeans = (ArrayList<ExerciseBean>) data.getSerializableExtra("subjectiveBeans");
                    double totalSubjectScore = 0;
                    double totalScore = exerciseListBean.getTotalScore() - exerciseListBean.getSubjectiveScore();
                    double shortAnswerScore = 0;
                    double caseAnalysisScore = 0;
                    double calculationScore = 0;
                    double inTrayScore = 0;
                    for (ExerciseBean bean : subjectiveBeans) {
                        if (bean != null && bean.hasMyScore()) {
                            if (bean.isShortAnswer()) {
                                shortAnswerScore += bean.getMyScore();
                            } else if (bean.isCaseAnalysis()) {
                                caseAnalysisScore += bean.getMyScore();
                            } else if (bean.isCalculation()) {
                                calculationScore += bean.getMyScore();
                            } else if (bean.isInTray()) {
                                inTrayScore += bean.getMyScore();
                            }
                            totalSubjectScore += bean.getMyScore();
                        }
                    }
                    totalScore += totalSubjectScore;
                    exerciseListBean.setShortAnswerScore(shortAnswerScore);
                    exerciseListBean.setAnalysisQuestScore(caseAnalysisScore);
                    exerciseListBean.setCalcQuestScore(calculationScore);
                    exerciseListBean.setOfficialDocScore(inTrayScore);
                    exerciseListBean.setTotalScore(totalScore);
//                    exerciseListInstallShortAnswer();
                    exerciseListInstall();
                    categoryNumberCard();
                }
            }
        }
    }

    /**
     * 将自评分的数据填充到简答题数据列表中
     */
//    private void exerciseListInstallShortAnswer() {
//        ExerciseBean shortAnwserBean;
//        for (int i = 0; i < shortAnswerBeans.size(); i++) {
//            shortAnwserBean = shortAnswerBeans.get(i);
//            if (shortAnwserBean != null && !shortAnwserBean.hasMyScore()) {
//                for (ExerciseBean subjectiveScoreBean : subjectiveScoreBeans) {
//                    if (subjectiveScoreBean != null && shortAnwserBean.getItemId() == subjectiveScoreBean.getItemId()) {
//                        shortAnswerBeans.set(i, subjectiveScoreBean);
//                    }
//                }
//            }
//        }
//
//    }

    /**
     * 组装试题
     */
    private void exerciseListInstall() {
        allAnswerBeans = new ArrayList<>();
        if (singleChoiceBeans != null) {
            allAnswerBeans.addAll(singleChoiceBeans);
            singleChoiceBeans.clear();
            singleChoiceBeans = null;
        }
        if (multipleChoiceBeans != null) {
            allAnswerBeans.addAll(multipleChoiceBeans);
            multipleChoiceBeans.clear();
            multipleChoiceBeans = null;

        }
        if (judgementChoiceBeans != null) {
            allAnswerBeans.addAll(judgementChoiceBeans);
            judgementChoiceBeans.clear();
            judgementChoiceBeans = null;
        }
        if (subjectiveBeans != null) {
            allAnswerBeans.addAll(subjectiveBeans);
            subjectiveBeans.clear();
            subjectiveBeans = null;
        }
        if (shortAnswerBeans != null) {
            shortAnswerBeans.clear();
            shortAnswerBeans = null;
        }
        if (caseAnalysisBeans != null) {
            caseAnalysisBeans.clear();
            caseAnalysisBeans = null;
        }
        if (calculationBeans != null) {
            calculationBeans.clear();
            calculationBeans = null;
        }
        if (inTrayBeans != null) {
            inTrayBeans.clear();
            inTrayBeans = null;
        }
        exerciseListBean.resetPaperItems(allAnswerBeans);
        exerciseListBean.setItemTotal(allAnswerBeans.size());

    }

    private CustomAlertDialog reExamDialog;

    private void showExitDialog() {
        if (reExamDialog == null) {
            reExamDialog = new CustomAlertDialog(context);
            reExamDialog.setContent("确定重考吗?");
            reExamDialog.setListener(new CustomAlertDialog.OnAlertClickListener() {
                @Override
                public void onRightClicked(View view) {
                    ExerciseActivity.start(context, examTitle, examId, ExerciseListBean.TYPE_ALL);
                    finish();
                }

                @Override
                public void onLeftClicked(View view) {

                }
            });
        }
        reExamDialog.show();
    }

    @Override
    public void onFragmentTrigger(int tag, Bundle bundle) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (reExamDialog != null) {
            reExamDialog.dismiss();
        }
    }
}
